<div class="row-fluid">
    <?php echo $this->render('/listados/menu.phtml'); ?>

    <div class="well well-small">
        <legend>Publicidad</legend>
        <form name="form_busqueda_publicidad" class="form-inline noPrint" method="GET" action="<?php echo $this->baseUrl(); ?>/admin/listados/publicidad">
            <div class="span12">
                <div class="span2" style="width: 90px;">
                    <label class="control-label">Desde</label>
                    <input id="b_desde" name="b_desde" value="<?php echo $this->b_desde ?>" class="input-small" type="text" />
                </div>   
                <div class="span2" style="width: 90px;">
                    <label class="control-label">Hasta</label>
                    <input id="b_hasta" name="b_hasta" value="<?php echo $this->b_hasta ?>" class="input-small" type="text" />
                </div>
                <div class="span2" style="width: 150px;">
                    <label class="control-label">Publicidad</label>
                    <select id="b_publicidad" name="b_publicidad" class="input-medium">
                        <option value="">Seleccione...</option>
                        <?php foreach ($this->publicidades as $publicidad) { ?>
                            <option value="<?php echo $publicidad->getId() ?>" <?php echo $this->b_publicidad == $publicidad->getId() ? "SELECTED" : "" ?> >
                                <?php echo $publicidad->getDescripcion() ?>
                            </option>
                        <?php } ?>
                    </select>
                </div>
                <div class="span2">
                    <label class="control-label">Sucursal</label>
                    <select id="sucursal" name="sucursal" class="input-medium">
                        <option value="0">Todas</option>
                        <?php foreach ($this->sucursales as $sucursal) { ?>
                        <option <?php echo $this->sucursal == $sucursal->getId() ? "selected" : "" ?> value="<?php echo $sucursal->getId(); ?>">
                            <?php echo $sucursal->getDescripcion(); ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="span2" style="margin-top:15px;">
                    <div class="btn-toolbar">
                        <input class="btn" value="Buscar" type="submit" />
                    </div>
                </div>
            </div>
        </form>

        <div class="row-fluid">
            Listando <?php echo count($this->creditos); ?> Creditos
            <div class="toolbar pull-right" style="margin: 5px;">
                <button type="button" onclick="PrintElement('#tabla_publicidad')" class="btn btn-inverse noPrint">
                    <i class=" icon-print icon-white"></i>  Imprimir
                </button>
            </div>
        </div>
        
        <div class="row-fluid">
            <h5 class="print">Publicidad<br/></h5>
            <table id="tabla_publicidad" class="tabla_reducida">
                <thead>
                <th>DNI</th><th>Apellido</th><th>Nombre</th><th>E-Mail</th><th>Publicidad</th>
                </thead>
                <tbody>
                    <?php if (count($this->creditos)) { ?>
                        <?php $credito = new Doctrine_Model_Entities_Credito(); ?>
                        <?php foreach ($this->creditos as $credito) { ?>
                            <tr id="<?php echo "persona{$credito->getCliente()->getId()}" ?>">
                                <td>
                                    <a href="<?php echo $this->baseUrl("usuarios/busqueda/obternerdatospersona/persona_id/{$credito->getCliente()->getId()}") ?>" onclick="agregaMarcaUrl('<?php echo "#persona{$credito->getCliente()->getId()}" ?>')">
                                    <?php echo "({$credito->getCliente()->getTipoDocumento()->getDescripcion()}) {$credito->getCliente()->getNroDocumento()}" ?>
                                    </a>
                                </td>
                                <td><?php echo $credito->getCliente()->getApellido() ?></td>
                                <td><?php echo $credito->getCliente()->getNombres() ?></td>
                                <td><?php echo $credito->getCliente()->getMail() ?></td>
                                <td><?php echo $credito->getPublicidad() ? $credito->getPublicidad()->getDescripcion() : "" ?></td>
                            </tr>
                        <?php } ?>
                    <?php } else { ?>
                        <tr>
                            <td colspan="5">Sin Resultados</td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>  
        </div>
    </div>
</div>

<div class="row-fluid">
    <div class="well well-small">
        <legend>Cantidad por Publicidad</legend>
        <table class="tabla_reducida">
            <thead>
                <tr>
                    <th>Publicidad</th><th>Cantidad</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($this->group_pulicidad as $publi => $group): ?>
                    <tr>
                        <td><?php echo $publi ?></td>
                        <td><?php echo $group ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>    
</div>

<script type="text/javascript">
    $(document).ready(function() {
        
        $("#tabla_publicidad").chromatable({
            width: "100%",  
            height: "350px",
            scrolling: "yes"
        });
        
        $("#b_desde").datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});
        $( "#b_hasta" ).datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});
        
    });

</script>

<script type="text/javascript">
    //Simple wrapper to pass a jQuery object to your new window
    function PrintElement(elem){
        Popup($(elem).html());
    }

    //Creates a new window and populates it with your content
    function Popup(data) {
        //Create your new window
        var w = window.open('', 'Publicidad <?php echo $this->b_desde ?> - <?php echo $this->b_hasta ?>', 'height=600,width=800');
        w.document.write('<html><head><title>Publicidad <?php echo $this->b_desde ?> - <?php echo $this->b_hasta ?></title>');
        //Include your stylesheet (optional)
        w.document.write('<link rel="stylesheet" href="<?php echo $this->baseUrl("bootstrap/css/bootstrap.css") ?>" type="text/css" />');
        w.document.write('</head><body>');
        w.document.write('<h2>Publicidad <?php echo $this->b_desde ?> - <?php echo $this->b_hasta ?></h2>');
        //Write your content
        w.document.write("<table class='table'>"+data+"</table>");
        w.document.write("<hr>");
        w.document.write($("#totales_ventas").html());
        w.document.write('</body></html>');
        w.print();
        w.close();

        return true;
    }
</script>